package 单周赛.history;

import java.util.Arrays;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Queue;

/**
 *
 */
public class 第301场单周赛 {

    public static void main(String[] args) {

        int[] amount = {3, 1, 0};
        System.out.println(fillCups(amount));

        SmallestInfiniteSet smallestInfiniteSet = new SmallestInfiniteSet();
        smallestInfiniteSet.addBack(2);
        System.out.println(smallestInfiniteSet.popSmallest());
        System.out.println(smallestInfiniteSet.popSmallest());
        System.out.println(smallestInfiniteSet.popSmallest());

    }

    public static int fillCups(int[] amount) {
        int count = 0;
        while (amount[0] + amount[1] + amount[2] > 0) {
            Arrays.sort(amount);
            if (amount[2] > 0) amount[2]--;
            if (amount[1] > 0) amount[1]--;
            count++;
        }
        return count;
    }

    static class SmallestInfiniteSet {

        private HashSet set = new HashSet();

        private Queue<Integer> priorityQueue = new PriorityQueue<>(1001, (o1, o2) -> o1 - o2);

        public SmallestInfiniteSet() {
            for (int num = 1; num <= 1000; num++) {
                set.add(num);
            }
            priorityQueue.addAll(set);
        }

        public int popSmallest() {
            Integer min = priorityQueue.poll();
            set.remove(min);
            return min;
        }

        public void addBack(int num) {
            if (!set.contains(num)) {
                priorityQueue.add(num);
                set.add(num);
            }
        }

    }

}
